# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgbase=curl
pkgname=('curl' 'libcurl' 'libcurl-devel')
pkgver=7.71.1
pkgrel=1
pkgdesc="Multi-protocol file transfer utility"
arch=('i686' 'x86_64')
url="https://curl.haxx.se"
license=('MIT')
depends=('ca-certificates')
makedepends=('heimdal-devel' 'libcrypt-devel' 'libidn2-devel' 'libmetalink-devel' 
             'libnghttp2-devel' 'libpsl-devel' 'libssh2-devel' 'openssl-devel' 'zlib-devel') #  'libcares-devel'
options=('!libtool' 'strip' '!debug')
source=("https://curl.haxx.se/download/${pkgname}-${pkgver}.tar.bz2"{,.asc}
        curl-7.58.0-msys2.patch)
sha256sums=('9d52a4d80554f9b0d460ea2be5d7be99897a1a9f681ffafe739169afd6b4f224'
            'SKIP'
            '4e4f89d40c8f7bfec2f687593f809fa96225b10da66be3788fe2b5d57e120dd0')
validpgpkeys=('27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2'   # Daniel Stenberg
              '914C533DF9B2ADA2204F586D78E11C6B279D5C91')  # Daniel Stenberg (old key)

prepare() {
  cd "${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/curl-7.58.0-msys2.patch
  autoreconf -fi
}

build() {
  cd "${pkgname}-${pkgver}"

  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --enable-debug \
    --enable-optimize \
    --enable-ipv6 \
    --disable-hidden-symbols \
    --disable-ares \
    --with-gssapi \
    --with-libidn \
    --with-libmetalink \
    --without-librtmp \
    --with-libssh2 \
    --without-spnego \
    --with-ssl \
    --without-gnutls \
    --with-zlib \
    --with-libpsl \
    --with-ca-bundle=/usr/ssl/certs/ca-bundle.crt \
    ac_cv_func_setmode=yes

  make
  make DESTDIR="${srcdir}/dest" install
}

package_curl() {
  depends=('ca-certificates' 'libcurl' 'libcrypt' 'libmetalink' 
           'libnghttp2' 'libpsl' 'openssl' 'zlib')
  groups=('base')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/

  # license
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

package_libcurl() {
  pkgdesc="Multi-protocol file transfer library (runtime)"
  depends=('ca-certificates' 'heimdal-libs' 'libcrypt' 'libidn2' 'libmetalink'
          'libnghttp2' 'libpsl' 'libssh2' 'openssl' 'zlib') #'libcares'
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_libcurl-devel() {
  pkgdesc="Libcurl headers and libraries"
  depends=("libcurl=${pkgver}" 'heimdal-devel' 'libcrypt-devel' 'libidn2-devel' 'libmetalink-devel' 
           'libnghttp2-devel' 'libpsl-devel' 'libssh2-devel' 'openssl-devel' 'zlib-devel') #'libcares-devel'
  options=('staticlibs')
  groups=('development')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
